package dao

import (
	"usplatformserver/global"
	"usplatformserver/internal/model"
	"usplatformserver/pkg/app"
)

// 查询患者信息列表
func (d *Dao) GetPatientList(organType int, option, beginTime, endTime string, page, pageSize int) ([]*model.PatientInfo, error) {
	patient := model.PatientInfo{OrganType: organType}
	pageOffset := app.GetPageOffset(page, pageSize)
	return patient.List(d.engine, option, beginTime, endTime, pageOffset, pageSize)
}

// 查询所有检查患者信息列表
func (d *Dao) GetPatientListWithoutType(option, beginTime, endTime string, page, pageSize int) ([]*model.PatientInfo, error) {
	patient := model.PatientInfo{}
	pageOffset := app.GetPageOffset(page, pageSize)
	return patient.ListWithoutType(d.engine, option, beginTime, endTime, pageOffset, pageSize)
}

// 查询所有检查患者信息列表
func (d *Dao) GetPatientListWithoutTypeAndPager(option, beginTime, endTime string) ([]*model.PatientInfo, error) {
	patient := model.PatientInfo{}
	global.Logger.Info("GetPatientListWithoutTypeAndPager")
	return patient.ListWithoutTypeAndPager(d.engine, option, beginTime, endTime)
}

// 查询患者总数
func (d *Dao) CountPatient(organType int, option, beginTime, endTime string) (int, error) {
	patient := model.PatientInfo{OrganType: organType}
	return patient.Count(d.engine, option, beginTime, endTime)
}

func (d *Dao) CountPatientWithoutType(option, beginTime, endTime string) (int, error) {
	patient := model.PatientInfo{}
	return patient.CountWithoutType(d.engine, option, beginTime, endTime)
}

// 查询最新患者信息
func (d *Dao) LastPatient() (*model.PatientInfo, error) {
	p := model.PatientInfo{}
	return p.LastPatient(d.engine)
}

func (d *Dao) GetPatientInfoByFileId(fileId int) (*model.PatientInfo, error) {
	p := model.PatientInfo{}
	return p.GetPatientInfoByFileId(d.engine, fileId)
}

func (d *Dao) StatisticsCheckedOrganCountList(beginTime, endTime string) ([]*model.CheckedOrganCount, error) {
	return model.StatisticsCheckedOrganCount(d.engine, beginTime, endTime)
}

func (d *Dao) StatisticsCheckedPatientCountList(beginTime, endTime string) ([]*model.CheckedPatientCount, error) {
	return model.StatisticsCheckedPatientCount(d.engine, beginTime, endTime)
}
